﻿package mortal.game.view.market.sale
{
    import Message.Game.*;
    import Message.Public.*;
    import com.greensock.layout.*;
    import com.mui.controls.*;
    import com.mui.utils.*;
    import flash.events.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.game.cache.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.display.*;
    import mortal.game.view.common.util.*;
    import mortal.mvc.core.*;

    public class MktMoneys extends GSprite
    {
        private var _bmpYuanbao:GBitmap;
        private var _bmpTongqian:GBitmap;
        private var _bmpYuanbaoBind:GBitmap;
        private var _bmpTongqianBind:GBitmap;
        private var _goldTextBox:TextBox;
        private var _coinTextBox:TextBox;
        private var _goldBindTextBox:TextBox;
        private var _coinBindTextBox:TextBox;

        public function MktMoneys()
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            var _loc_1:* = GlobalStyle.textFormatBai;
            _loc_1.size = 11;
            this._goldTextBox = this.createTextBox(0, 0);
            this._bmpYuanbao = UIFactory.bitmap(ImagesConst.Yuanbao, 134, 1, this);
            this.pushUIToDisposeVec(UIFactory.gTextField(GameDefConfig.instance.getEPrictUnitName(EPriceUnit._EPriceUnitGold) + " :", 3, 2, 80, 20, this, _loc_1));
            this._coinTextBox = this.createTextBox(1, 0);
            this._bmpTongqian = UIFactory.bitmap(ImagesConst.Jinbi, 133, 26, this);
            this.pushUIToDisposeVec(UIFactory.gTextField(GameDefConfig.instance.getEPrictUnitName(EPriceUnit._EPriceUnitCoin) + " :", 3, 27, 80, 20, this, _loc_1));
            this._goldBindTextBox = this.createTextBox(0, 1);
            this._bmpYuanbaoBind = UIFactory.bitmap(ImagesConst.Yuanbao_bind, 293, 1, this);
            this.pushUIToDisposeVec(UIFactory.gTextField(GameDefConfig.instance.getEPrictUnitName(EPriceUnit._EPriceUnitGoldBind) + " :", 162, 2, 80, 20, this, _loc_1));
            this._coinBindTextBox = this.createTextBox(1, 1);
            this._bmpTongqianBind = UIFactory.bitmap(ImagesConst.Jinbi_bind, 292, 26, this);
            this.pushUIToDisposeVec(UIFactory.gTextField(GameDefConfig.instance.getEPrictUnitName(EPriceUnit._EPriceUnitCoinBind) + " :", 162, 27, 80, 20, this, _loc_1));
            NetDispatcher.addCmdListener(ServerCommand.MoneyUpdate, this.updateMoney);
            this.addEventListener(Event.ADDED_TO_STAGE, this.onAddToStage);
            return;
        }// end function

        protected function onAddToStage(event:Event) : void
        {
            this.removeEventListener(Event.ADDED_TO_STAGE, this.onAddToStage);
            this.updateMoney();
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            NetDispatcher.removeCmdListener(ServerCommand.MoneyUpdate, this.updateMoney);
            this.removeEventListener(Event.ADDED_TO_STAGE, this.onAddToStage);
            this._bmpYuanbao.dispose(param1);
            this._bmpTongqian.dispose(param1);
            this._bmpYuanbaoBind.dispose(param1);
            this._bmpTongqianBind.dispose(param1);
            this._goldTextBox.dispose(param1);
            this._coinTextBox.dispose(param1);
            this._goldBindTextBox.dispose(param1);
            this._coinBindTextBox.dispose(param1);
            this._bmpYuanbao = null;
            this._bmpTongqian = null;
            this._bmpYuanbaoBind = null;
            this._bmpTongqianBind = null;
            this._goldTextBox = null;
            this._coinTextBox = null;
            this._goldBindTextBox = null;
            this._coinBindTextBox = null;
            return;
        }// end function

        private function createTextBox(param1:int, param2:int, param3:int = 157, param4:int = 23) : TextBox
        {
            var _loc_6:TextBox = null;
            var _loc_5:* = GlobalStyle.textFormatHuang;
            _loc_5.align = AlignMode.RIGHT;
            _loc_6 = UICompomentPool.getUICompoment(TextBox);
            _loc_6.createDisposedChildren();
            _loc_6.defaultTextFormat = _loc_5;
            _loc_6.textFieldHeight = 18;
            _loc_6.bgHeight = param4;
            _loc_6.bgWidth = param3;
            _loc_6.textField.y = 2;
            _loc_6.textFieldWidth = 132;
            _loc_6.x = param2 * 160;
            _loc_6.y = param1 * 26;
            this.addChild(_loc_6);
            return _loc_6;
        }// end function

        private function updateMoney(param1:Object = null) : void
        {
            var _loc_2:* = Cache.instance.role.money;
            this.setCoinAmount(_loc_2.coin);
            this.setCoinBindAmount(_loc_2.coinBind);
            this.setGoldAmount(_loc_2.gold);
            this.setGoldBindAmount(_loc_2.goldBind);
            return;
        }// end function

        public function setCoinAmount(param1:int) : void
        {
            if (this.parent == null)
            {
                return;
            }
            var _loc_2:* = MoneyUtil.getCoinHtml(param1);
            if (_loc_2 == this._coinTextBox.htmlText)
            {
                return;
            }
            this._coinTextBox.htmlText = MoneyUtil.getCoinHtml(param1);
            return;
        }// end function

        public function setCoinBindAmount(param1:int) : void
        {
            if (this.parent == null)
            {
                return;
            }
            var _loc_2:* = MoneyUtil.getCoinHtml(param1);
            if (_loc_2 == this._coinBindTextBox.htmlText)
            {
                return;
            }
            this._coinBindTextBox.htmlText = MoneyUtil.getCoinHtml(param1);
            return;
        }// end function

        public function setGoldAmount(param1:int) : void
        {
            if (this.parent == null)
            {
                return;
            }
            var _loc_2:* = MoneyUtil.getCoinHtml(param1);
            if (_loc_2 == this._goldTextBox.htmlText)
            {
                return;
            }
            this._goldTextBox.htmlText = MoneyUtil.getGoldHtml(param1);
            return;
        }// end function

        public function setGoldBindAmount(param1:int) : void
        {
            if (this.parent == null)
            {
                return;
            }
            var _loc_2:* = MoneyUtil.getCoinHtml(param1);
            if (_loc_2 == this._goldBindTextBox.htmlText)
            {
                return;
            }
            this._goldBindTextBox.htmlText = MoneyUtil.getGoldHtml(param1);
            return;
        }// end function

    }
}
